<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>天气案例</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气{{info}}</h2>
        <!-- @xxx="yyy" yyy可以写一些简单的语句 -->
        <!-- <button @click="isHot = !isHot">切换天气</button> -->
        <button @click="changeWeather">切换天气</button>
    </div>
</body>
<!--   JS   -->
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽'
                }
            },
            methods: {
                changeWeather(){
                     this.isHot = !this.isHot
                     alert(1)
                }
            },
            watch:{
                isHot:{
                    immediate:true,//初始化时调用handler
                    //isHot发生改变时
                    handler(newValue,oldValue){
                        console.log('ishot修改了',newValue,oldValue)
                    }
                }
            }
        })
        //属性是在对象里的，变量是单独声明并赋值，这里没有定义isHot变量，只有对象里的isHot属性
        //对象的属性名是字符串，会隐式转换
        /* vm.$watch('isHot',{
            immediate:true,//初始化时调用handler
            //isHot发生改变时
            handler(newValue,oldValue){
                console.log('ishot修改了',newValue,oldValue)
            }
        }) */
    </script>
</html>